# The target library's name
LIBRARY = plplot

# pkg-config's name for the PLplot library
PKG_CONFIG_PLPLOT = plplotd

# Commands to use for ocamlbuild and ocamlfind (in case they are not in $PATH)
OCAMLBUILD = ocamlbuild -tag debug
OCAMLFIND = ocamlfind

export CAMLIDL_LIB_DIR = -L$(shell ocamlc -where)
export CAMLIDL_LIB = -lcamlidl
export PLPLOT_CFLAGS = $(shell pkg-config --cflags ${PKG_CONFIG_PLPLOT})
export PLPLOT_LIBS = $(shell pkg-config --libs ${PKG_CONFIG_PLPLOT})
export PLPLOT_LIBS_DIRS = $(shell pkg-config --libs-only-L ${PKG_CONFIG_PLPLOT})
export PLPLOT_LIBS_LIBS = $(shell pkg-config --libs-only-l ${PKG_CONFIG_PLPLOT})

# Where ocamlbuild put the build files
BUILD_DIR = _build/

# Default to building bytecoode and native code libraries
all: byte opt

byte:
	$(OCAMLBUILD) $(LIBRARY).cma

opt:
	$(OCAMLBUILD) $(LIBRARY).cmxa

# (Un)Installation using ocamlfind
install:
	$(OCAMLFIND) install $(LIBRARY) \
	    META \
	    $(BUILD_DIR)*plplot.cmi \
	    $(BUILD_DIR)*plplot.cma \
	    $(BUILD_DIR)*plplot.cmxa \
	    $(BUILD_DIR)*plplot_stubs.so \
	    $(BUILD_DIR)*plplot_stubs.a \
	    $(BUILD_DIR)*plplot.a

uninstall:
	$(OCAMLFIND) remove $(LIBRARY)

# Clean up the build process using ocamlbuild
clean:
	$(OCAMLBUILD) -clean

